package CCRMClient.GUI;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JLabel;

import java.awt.Font;

import javax.swing.JButton;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import javax.swing.JTextField;

import java.awt.Color;

import javax.swing.SwingConstants;
import javax.swing.border.LineBorder;

import CCRMClient.ClientStart;

import java.awt.FlowLayout;
import java.awt.BorderLayout;

/**
 * this class is the customer manage screen with operation witch are managing customer details
 * @author Ola
 *
 */
public class CustomerManage extends JPanel 
{
	
	private JLabel lblCustomerManagement;
	private JButton btnAddCustomer;
	private JButton btnUpadateCustomer;
	private JButton btnSearchCustomer;
	private JButton btnChangeStatus;
	private JButton btnQuit;// this button will return you to main portal
	private JButton btnAddPermission;
	/**
	 * Create customer manage panel
	 */
	public CustomerManage() {
		initialize();// this method will create a customer manage panel

	}
	private void initialize(){
		setSize (565,549);
		setBorder(new LineBorder(new Color(0, 0, 0), 1, true));
		setBackground(Color.WHITE);
		setLayout(null);
		
		
		
		/**
		 * create label
		 */
		
		lblCustomerManagement= new JLabel("CCRM-Customer Management");
		lblCustomerManagement.setFont(new Font("David", Font.BOLD, 26));
		lblCustomerManagement.setForeground(Color.RED);
		lblCustomerManagement.setBounds(79, 31, 384, 40);
		add(lblCustomerManagement);
		/**
		 * create add customer button
		 */
		
			
		 btnAddCustomer=new  JButton("Add Customer");
		btnAddCustomer.setFont(new Font("David", Font.PLAIN, 16));
		btnAddCustomer.addActionListener(new BtnAddCustomerActionListener());
		btnAddCustomer.setBounds(174, 99, 212, 40);
		add(btnAddCustomer);
		
		
		/**
		 * create update customer button
		 */
		
		btnUpadateCustomer=new  JButton("Update Customer");
		btnUpadateCustomer.setFont(new Font("David",Font.PLAIN, 16));
		btnUpadateCustomer.addActionListener(new BtnUpdateCustomerActionListener());
		btnUpadateCustomer.setBounds(174, 172, 212, 40);
		add(btnUpadateCustomer);
		/**
		 * create search customer button
		 */
		
	    btnSearchCustomer=new  JButton("Search Customer");
		btnSearchCustomer.setFont(new Font("David",Font.PLAIN, 16));
		btnSearchCustomer.addActionListener(new BtnSearchCustomerActionListener() );
		btnSearchCustomer.setBounds(174, 247, 212, 40);
		add(btnSearchCustomer);
		
		/**
		 * create change customer status button witch can enable or disable customer 
		 */
		 btnChangeStatus=new  JButton("Change Customer Status");
		btnChangeStatus.setFont(new Font("David",Font.PLAIN, 16));
		btnChangeStatus.addActionListener(new BtnChangeCustomerStatusActionListener());
		btnChangeStatus.setBounds(174, 310, 212, 40);
		add(btnChangeStatus);
		
		/**
		 * create Quit button witch will return us to main portal
		 */
		
		 btnQuit=new  JButton("Quit");
		btnQuit.setFont(new Font("David",Font.PLAIN, 16));
		btnQuit.addActionListener(new BtnCancelActionListener()) ;
		btnQuit.setBounds(236, 466, 88, 31);
		add(btnQuit);

		btnAddPermission=new  JButton("Add Permission");
		btnAddPermission.setFont(new Font("David",Font.PLAIN, 16));
		btnAddPermission.addActionListener(new BtnAddPermisionActionListener()) ;
		btnAddPermission.setBounds(174, 379, 212, 40);
		add(btnAddPermission);
} 
	
	/**
	 * This inner class implements event listener for pressing cancel button
	 * @author Ola
	 *
	 */
	private class BtnCancelActionListener implements ActionListener {
		public void actionPerformed(ActionEvent arg0) {
			ClientStart.panelSwicher(new EmployeePortal());
		}
}
	/**
	 * This inner class implements event listener for pressing AddCustomer button
	 * @author Ola
	 *
	 */
	private class BtnAddCustomerActionListener implements ActionListener{
		public void actionPerformed(ActionEvent arg0) {
			if ((!ClientStart.user.getPosition().equals("Customer relations")) )
				JOptionPane.showMessageDialog(null, "You are not authorized to do this action!", "Security Issue", JOptionPane.ERROR_MESSAGE);
			else
			ClientStart.panelSwicher(new AddCustomerScreen());
		}
		
	}
	/**
	 * This inner class implements event listener for pressing UpdateCustomer button
	 * @author Ola
	 *
	 */
	  private class BtnUpdateCustomerActionListener implements ActionListener {
		 public void actionPerformed(ActionEvent arg0) {
			ClientStart.panelSwicher(new UpdateCustomerScreen());
		}
	}
	  /**
	   * This inner class implements event listener for pressing UpdateCustomer button
	   * @author Ola
	   *
	   */
	  private class BtnSearchCustomerActionListener implements ActionListener{
		  public void actionPerformed(ActionEvent arg0) {
				ClientStart.panelSwicher(new SearchCustomerScreen());
			}
	  }
	  /**
	   * This inner class implements event listener for pressing ChangeCustomerStatus button
	   * @author Ola
	   *
	   */
	  private class BtnChangeCustomerStatusActionListener implements ActionListener{
		  public void actionPerformed(ActionEvent arg0) {
			ClientStart.panelSwicher(new ChangeCustomerStatusScreen());
			}
	  }
	  /**
	   * This inner class implements event listener for pressing AddPermission button
	   * @author Ola
	   *
	   */
	  private class BtnAddPermisionActionListener implements ActionListener{
		  public void actionPerformed(ActionEvent arg0) {
			  ClientStart.panelSwicher(new AddCustomerPermission());
			}
	  }
	  
	  
}
